// pages/operation/operation_me/operation_me.js
const urls = require('../../../utils/url.js').urls
const http = require('../../../utils/url.js').http
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {

    ztArray: [
      { "zt": "空闲中", "id": "0" },
      { "zt": "工作中", "id": "1" },
      { "zt": "锁定", "id": "2" },
      { "zt": "休假", "id": "3" }
    ],
    zt:'工作中',
    ztid:'',
    nc: '',
    tx: '',
    name: '',
    zj: '',
    sj: '',
    fj: '',
    dw: '',
    bm: '',
    dz: '',


  },
  // 状态事件
  bindztChange :function(event){
    var that = this;
    var index =  event.detail.value;
    var zt = that.data.ztArray[index].zt;
    var ztid = that.data.ztArray[index].id;
  
    var  param = {
      userid: app.globalData.openid ,                                         //用户id
       state:ztid  
    }
    http(urls.workState,param,function(res){

        wx.showToast({
          title: res.msg,
        })
      that.setData({
        zt: zt,
        ztid: ztid
      })
    })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.showNavigationBarLoading();
    var param = {
      openid: app.globalData.openid                                           //openId

    };
    http(urls.details, param, function (res) {
      console.log(res)
      that.setData({
        nc: res.data.nickname,
        tx: res.data.avatarurl,
        name: res.data.realname,
        zj: res.data.zjh,
        sj: res.data.phone,
        fj: res.data.room,
        dw: res.data.comame,
        bm: res.data.departname,
        dz: res.data.dompany_address,
      })
      wx.hideNavigationBarLoading();
    })


  },
  alter_name: function (event) {
    wx.setStorageSync('user_type', 0)
    wx.setStorageSync("user_name", this.data.name)
    wx.navigateTo({
      url: '../../../pages/user/alter/alter',
    })

  },
  alter_zj: function (event) {
    wx.setStorageSync('user_type', 1)
    wx.setStorageSync("user_name", this.data.zj)
    wx.navigateTo({
      url: '../../../pages/user/alter/alter',
    })

  },
  alter_sj: function (event) {
    wx.setStorageSync('user_type', 2)
    wx.setStorageSync("user_name", this.data.sj)
    wx.navigateTo({
      url: '../../../pages/user/alter/alter',
    })

  },
  alter_fj: function (event) {
    wx.setStorageSync('user_type', 3)
    wx.setStorageSync("user_name", this.data.fj)
    wx.navigateTo({
      url: '../../../pages/user/alter/alter',
    })

  },
  choose_dw: function (event) {
    wx.setStorageSync('user_type', 4)
    wx.setStorageSync("user_name", this.data.dw)
    wx.navigateTo({
      url: '../../../pages/user/choose/choose',
    })

  },
  choose_bm: function (event) {
    wx.setStorageSync('user_type', 5)
    wx.setStorageSync("user_name", this.data.bm)
    wx.navigateTo({
      url: '../../../pages/user/choose/choose',
    })

  },
  choose_dz: function (event) {
    wx.setStorageSync('user_type', 6)
    wx.setStorageSync("user_name", this.data.dz)
    wx.navigateTo({
      url: '../../../pages/user/address/address',
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (getCurrentPages().length != 0) {
      //刷新当前页面的数据
      getCurrentPages()[getCurrentPages().length - 1].onLoad()
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  
})